<?php
declare (strict_types = 1);

namespace app\model;

use think\Model;
use think\model\relation\BelongsTo;

/**
 * @mixin \think\Model
 */
class AdminUnlockRecord extends Model
{
    //
    protected $autoWriteTimestamp = true;

    public function staff(): BelongsTo {
        return $this->belongsTo(AdminStaff::class, 'staff_id')->bind([
            'staff_name' => 'name'
        ]);
    }

    public function school() {
        return $this->belongsTo(AdminSchool::class, 'school_id')->bind([
            'school_name' => 'name'
        ]);
    }

    public function dormitory(): BelongsTo {
        return $this->belongsTo(AdminDormitory::class, 'dormitory_id')->bind([
            'dormitory_name' => 'name'
        ]);
    }

    public function student(): BelongsTo {
        return $this->belongsTo(AdminStudentDormitory::class, 'student_dormitory_id')->bind([
            'student_dormitory_name' => 'name'
        ]);
    }

    public function getRequestIpAttr($value)
    {
         return long2ip($value);
    }

    public function getUnlockTypeTextAttr($value,$data)
    {
        $type = [0=>'蓝牙',1=>'SIM卡',2 => '在线密码', 3 => 'IC卡', 4=> '离线密码'];
        return $type[$data['unlock_type']];
    }

    public function getUnlockStatusTextAttr($value,$data)
    {
        $type = [0=>'失败',1=>'成功'];
        return $type[$data['unlock_status']];
    }
}
